<template><!--必须有template和div标签-->
  <div class="app-container"><!-- 调用定义的接口方法，得到接口返回的数据-->
    <!-- 表格 -->
    <el-table
      :data="list"
      element-loading-text="数据加载中"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="title" label="名称" width="80" />

      <el-table-column prop="imageUrl" label="图片地址" />

      <el-table-column prop="linkUrl" label="链接地址" />

      <el-table-column prop="sort" label="排序" />

      <el-table-column prop="gmtCreate" label="添加时间" width="160"/>


      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/banner/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

       <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
    
  </div>
</template>

<script>

import banner from '@/api/edu/banner'
export default {
    data(){
        return{
            list:null,
            page:1,//当前页
            limit:10,//每页最大纪录数
            total:0//总记录数
        }
    },
    created(){
        this.getList()
    },
    methods:{

        removeDataById(id){
         this.$confirm('此操作将删除banner记录, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(()=>{
              banner.deleteBanner(id)
              .then(()=>{
                  this.$message({
                      type:'success',
                      message:'删除成功'
                  })
                  this.getList()
              })
          })
          .catch(()=>{})
        },
        getList(page=1){
            banner.getBannerList(this.page,this.limit)
            .then(response=>{
                this.list=response.data.records
                this.total=this.list.length
            })
        }
    }
}
</script>